$(function() {
	var oStar = document.getElementById("star");
	var aLi = oStar.getElementsByTagName("img");
	var i = iScore = iStar = 0;

	for (i = 1; i <= aLi.length; i++) {
		aLi[i - 1].index = i;

		// 鼠标移过显示分数
		aLi[i - 1].onmouseover = function() {
			fnPoint(this.index);
		};

		// 鼠标离开后恢复上次评分
		aLi[i - 1].onmouseout = function() {
			fnPoint();
		};

		// 点击后进行评分处理
		aLi[i - 1].onclick = function() {
			iStar = this.index;
			$("#scores").val(iStar);
		}
	}

	// 评分处理
	function fnPoint(iArg) {
		// 分数赋值
		iScore = iArg || iStar;
		for (i = 0; i < aLi.length; i++)
			aLi[i].src = i < iScore ? staticPath + "/images/pingjia1.png" : staticPath + "/images/pingjia2.png";
	}

	// 控制文本域的字数
	statInputNum();
})

function statInputNum() {
	var max = 100;
	$("textarea").attr("maxlength", max);
	$("textarea").on('input propertychange', function() {
		var _value = $(this).val().replace(/\n/gi, "");
	});
}

function save(){
	var scores = $("#scores").val();
	if(scores == ''){
		myalert("您还没有打分哦");
		return false;
	}
	var content = $("#content").val();
	if(content == ''){
		myalert("请发表一下你的看法吧");
		return false;
	}
	showLoading();
	$.ajax({
		type : "post",
		url : appPath + "/comments/addComment.html",
		data : {
			scores : scores,
			token : $.cookie("token"),
			goodsOrderId : $("#goodsOrderId").val(),
			image : $("#image").val(),
			image2 : $("#image2").val(),
			image3 : $("#image3").val(),
			image4 : $("#image4").val(),
			image5 : $("#image5").val(),
			content : $("#content").val()
		},
		success : function(result) {
			hideLoading();
			myalert(result.msg, function() {
				if (result.code == '1') {
					gotoHtml('/buyer/buyer.htm');
				} else if (result.code == '-1') {
					window.location = appPath + "/member/login.htm";
				}
			});
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			hideLoading();
			myalert("系统异常，请稍后再试");
		}
	});
}